//
//  OrganationITypeChooseViewController.m
//  ShangHaiTuJI
//
//  Created by xiaoxiangtuji on 2017/10/11.
//  Copyright © 2017年 xiaoxiangtuji. All rights reserved.
//

#import "OrganationITypeChooseViewController.h"
#import "ScreeningCell.h"
@interface OrganationITypeChooseViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property(nonatomic,strong)UICollectionView *collectionView;
@property(nonatomic,strong)UICollectionViewFlowLayout *flowLayout;
@property(nonatomic,strong)NSArray *firstArray;
@property(nonatomic,strong)NSArray *secondArray;
@property(nonatomic,strong)NSArray *thirdrray;
@property(nonatomic,strong)NSArray *forthArray;
@property(nonatomic,strong)NSArray *fifthArray;
@property(nonatomic,strong)NSArray *sixthArray;
@property(nonatomic,strong)NSArray *seventhArray;
@property(nonatomic,strong)NSArray *eighthArray;
@property(nonatomic,strong)NSArray *ninthArray;
@property(nonatomic,strong)NSArray *tenthArray;
@end

@implementation OrganationITypeChooseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createAndLayoutCollectionView];
    // Do any additional setup after loading the view.
}
-(void)createAndLayoutCollectionView{
    self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
    self.flowLayout.itemSize = CGSizeMake(scaleLeftAndRight(75), scaleTopAndBottom(30));
    self.flowLayout.minimumLineSpacing = 10;
    self.flowLayout.minimumInteritemSpacing = 10;
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 30, WIDTH, HEIGHT - 30) collectionViewLayout:self.flowLayout];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.collectionView];
    self.collectionView.allowsMultipleSelection = YES;
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    [self.collectionView registerClass:[ScreeningCell class] forCellWithReuseIdentifier:@"ScreeningCell"];
    [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
    [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer"];
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 10;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    switch (section) {
        case 0:
        {
            return self.firstArray.count - 1;
        }
            break;
        case 1:
        {
            return self.secondArray.count - 1;
        }
            break;
        case 2:
        {
            return self.thirdrray.count - 1;
        }
            break;
        case 3:
        {
            return self.forthArray.count - 1;
        }
            break;
        case 4:
        {
            return self.fifthArray.count - 1;
            
        }
            break;
        case 5:
        {
            return self.sixthArray.count - 1;
            
        }
            break;
        case 6:
        {
            return self.seventhArray.count - 1;
            
        }
            break;
        case 7:
        {
            return self.eighthArray.count - 1;
            
        }
            break;
        case 8:
        {
            return self.ninthArray.count - 1;
            
        }
            break;
        case 9:
        {
            return self.tenthArray.count - 1;
            
        }
            break;
        default:
            break;
    }
    return 0;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    ScreeningCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ScreeningCell" forIndexPath:indexPath];
    if (indexPath.section == 0) {
        cell.label.text = self.firstArray[indexPath.row + 1];
    }else if (indexPath.section == 1){
        cell.label.text = self.secondArray[indexPath.row + 1];
    }else if (indexPath.section == 2){
        cell.label.text = self.thirdrray[indexPath.row + 1];
    }else if (indexPath.section == 3){
        cell.label.text = self.forthArray[indexPath.row + 1];
    }else if (indexPath.section == 4){
        cell.label.text = self.fifthArray[indexPath.row + 1];
    }else if (indexPath.section == 5){
        cell.label.text = self.sixthArray[indexPath.row + 1];
    }else if (indexPath.section == 6){
        cell.label.text = self.seventhArray[indexPath.row + 1];
    }else if (indexPath.section == 7){
        cell.label.text = self.eighthArray[indexPath.row + 1];
    }else if (indexPath.section == 8){
        cell.label.text = self.ninthArray[indexPath.row + 1];
    }else{
        cell.label.text = self.tenthArray[indexPath.row + 1];
    }
    return cell;
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(0, 15, 0, 15);
}
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if ([kind isEqual:UICollectionElementKindSectionHeader]) {
        UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"header" forIndexPath:indexPath];
        for (UIView *views in view.subviews) {
            [views removeFromSuperview];
        }
        if (indexPath.section == 0) {
            [self createTittleLabel:view WithTitle:self.firstArray[0]];
        }else if (indexPath.section == 1){
            [self createTittleLabel:view WithTitle:self.secondArray[0]];
        }else if (indexPath.section == 2){
            [self createTittleLabel:view WithTitle:self.thirdrray[0]];
        }else if (indexPath.section == 3){
            [self createTittleLabel:view WithTitle:self.forthArray[0]];
        }else if (indexPath.section == 4){
            [self createTittleLabel:view WithTitle:self.fifthArray[0]];
        }else if (indexPath.section == 5){
            [self createTittleLabel:view WithTitle:self.sixthArray[0]];
        }else if (indexPath.section == 6){
            [self createTittleLabel:view WithTitle:self.seventhArray[0]];
        }else if (indexPath.section == 7){
            [self createTittleLabel:view WithTitle:self.eighthArray[0]];
        }else if (indexPath.section == 8){
            [self createTittleLabel:view WithTitle:self.ninthArray[0]];
        }else{
            [self createTittleLabel:view WithTitle:self.tenthArray[0]];;
        }
        return view;
    }else{
        UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer" forIndexPath:indexPath];
        [self createLineView:view];
        return view;
    }
    
}

-(void)createTittleLabel:(UICollectionReusableView *)view WithTitle:(NSString *)title{
    UILabel *_label;
    _label = [[UILabel alloc] init];
    _label.textAlignment = NSTextAlignmentCenter;
    _label.adjustsFontSizeToFitWidth = YES;
    _label.text = title;
    _label.layer.borderWidth = 1.0f;
    _label.layer.borderColor = [UIColor lightGrayColor].CGColor;
    _label.textColor = [UIColor blackColor];
    [view addSubview:_label];
    [_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view.mas_left).offset(15);
        make.width.mas_equalTo(scaleLeftAndRight(75));
        make.top.equalTo(view.mas_top).offset(10);
        make.bottom.equalTo(view.mas_bottom).offset(-10);
    }];
    _label.layer.cornerRadius = 4;
    _label.layer.masksToBounds = YES;
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
//    if (section == 0) {
//        return CGSizeMake(20.0f, 20.0f);
//    }
//    return CGSizeMake(WIDTH, scaleTopAndBottom(40));
    return CGSizeMake(WIDTH - 30, scaleTopAndBottom(15));
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
//    return CGSizeMake(WIDTH, scaleTopAndBottom(30));
    return CGSizeMake(scaleLeftAndRight(75) + 15, scaleTopAndBottom(30) + 20);
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    ScreeningCell *cell = (ScreeningCell *)[collectionView cellForItemAtIndexPath:indexPath];
    cell.label.layer.borderColor = [UIColor yellowColor].CGColor;
    cell.label.textColor = [UIColor yellowColor];
    
}
-(void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
    ScreeningCell *cell = (ScreeningCell *)[collectionView cellForItemAtIndexPath:indexPath];
    cell.label.layer.borderColor = [UIColor lightGrayColor].CGColor;
    cell.label.textColor = [UIColor blackColor];
    
}

-(void)createLineView:(UICollectionReusableView *)view{
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = [UIColor lightGrayColor];
    [view addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view.mas_left).offset(15);
        make.right.equalTo(view.mas_right).offset(-15);
        make.height.mas_equalTo(0.5);
        make.centerY.equalTo(view.mas_centerY);
    }];
}
#pragma mark -数据懒加载
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
